/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.sucresale.presentation;

import com.sucresale.entities.Users;
import com.sucresale.facade.UserSessionBeanLocal;
import com.sucresale.utilities.SucreSaleConstants;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpSession;

/**
 *
 * @author Users
 */
@ManagedBean(name="UserAdminManagedBean")
@RequestScoped
public class UserAdminManagedBean {

    @EJB
    private UserSessionBeanLocal userManagedBean;


    //Forgot Your Password Instance Variables
    private String recoverYourPasword;
    private String username;
    private String password;

    //Create new user Instance Variable
    //private String


    /** Creates a new instance of UserAdminManagedBean */
    public UserAdminManagedBean() {
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getRecoverYourPasword() {
        return recoverYourPasword;
    }

    public void setRecoverYourPasword(String recoverYourPasword) {
        this.recoverYourPasword = recoverYourPasword;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    

    public String forgotYourPassword(){

        return "";

    }

      public String checkCredentials() {

        String page = "crendentialsError";

        if(userManagedBean.checkCredentials(username, password)){

            Users _tempUser = userManagedBean.getAllInfoFromUser(username);

            HttpSession session = (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(true);
            session.setMaxInactiveInterval(SucreSaleConstants.MAX_INACTIVE_INTERVAL_IN_SECONDS);
            session.setAttribute("username", _tempUser.getUsername());
            session.setAttribute("Name", _tempUser.getCompleteName());
            //session.setAttribute("Address", _tempUser.getAddresses().get(0));
            session.setAttribute("PhoneNumber", _tempUser.getHomePhoneNumber());
            session.setAttribute("CellNumber", _tempUser.getCellNumber());
            session.setAttribute("Picture", _tempUser.getPicture());

            page = "selection";
        }

        return page;

    }




    public String createNewUser(){

        return "";
    }

}
